/****************************************************
	文件：LoadingController.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2021/3/22 17:20:39
	功能：Loading 控制器
*****************************************************/

using HTFW.Core;
using HTFW.Scene;

namespace HTFW.UI
{
    public class LoadingController : ControllerBase<LoadingView, LoadingModel>
    {
        public LoadingController(LoadingView view, LoadingModel model) : base(view, model)
        {
        }


        //------------------------------ Events ------------------------------//

        #region Events

        protected override void RegisterEvents()
        {
            AddEvent(EventType.UpdateSceneLoadProgress, UpdateSceneLoadProgressHandle);
        }

        void UpdateSceneLoadProgressHandle(params object[] args)
        {
            mModel.LoadProgress.Value = (int) args[0];
        }

        #endregion


        //------------------------------ Model ------------------------------//

        #region Model

        protected override void InitModel()
        {
            mModel.LoadProgress.Subscribe(OnLoadProgressChanged);
        }

        void OnLoadProgressChanged(int o, int n)
        {
            if (mView == null) return;
            if (SceneManager.Instance.IsAlreadyLoaded) return;
            mView.SetProgress(n);
        }

        #endregion


        //------------------------------ View ------------------------------//

        #region View

        protected override void InitView()
        {
        }

        #endregion
    }
}